package p300;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Leetcode_338 {
    public int[] countBits(int num) {
        int[] result = new int[num + 1];
        for (int i = 0; i <= num / 2; i++) {
            if (i % 2 == 0) {
                result[i] = result[i / 2];
            } else {
                result[i] = result[i / 2] + 1;
            }
            result[i * 2] = result[i];
            if (i * 2 + 1 <= num) {
                result[i * 2 + 1] = result[i] + 1;
            }
        }
        return result;
    }

    public static void main(String[] args) {

        Leetcode_338 l = new Leetcode_338();
        System.out.println(Arrays.toString(l.countBits(2)));
    }
}
